<?php

namespace app\common\model\cast;

use app\common\utils\Utils;
use think\Db;
use think\Model;
use traits\model\SoftDelete;

class Item extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'self_cast_item';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text',
        'image_text'
    ];
    public function getImageTextAttr($value, $data) {
        $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');
        return cdnurl($value, true);
    }

    
    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    /**获取分类id*/
    public function getIds($item_id) {
        $ids = Db::name('self_cate_to_item')->where(['item_id' => $item_id])->column('category_id');

        return Utils::implodeArr($ids);
    }


}
